package com.example.qggoodsprovider.mapper;

import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Options;
import org.apache.ibatis.annotations.Select;



import java.util.List;
import java.util.Map;
@Mapper
public interface GoodsMapper {
    @Select("select * from goods")
    public List<Map> getAllGoods();

    @Select("select count(1) from qggoodstempstock where goodsId=#{goodsId}")
    public int getQgTotalByGoodsId(int goodsId);

    @Select( "select stock from goods where id=#{goodsId}" )
    public int getStock(int goodsId);

    @Insert("insert into qggoodstempstock values(default,#{goodsId},#{userId},default,default,now())")
    //把自动生成的id保存到map中
    @Options(useGeneratedKeys = true,keyColumn = "id",keyProperty = "id")
    public int addTempSotck(Map map);

    //查询临时库存表
    @Select( "select count(1) from qggoodstempstock where goodsId=#{goodsId} and userId=#{userId}" )
    public int getCountByGoodsIdUid(Map map);
    //根据goodsid查询商品信息
    @Select( "select * from goods where id=#{goodsId}" )
    public Map getById(int goodsId);
}
